from owlready2 import *

onto = get_ontology('http://test.org/onto.owl')
with onto:
    print('1. disjoint classes')
    class Drug(Thing):pass
    class ActivePrinciple(Thing):pass
    AllDisjoint([Drug, ActivePrinciple])
    print('2. disjoint properties')
    print('3. different individuals')
    acetaminophen = ActivePrinciple('acetaminophen')
    aspirin = ActivePrinciple('aspirin')
    AllDifferent([acetaminophen, aspirin])
    print('4. query and modifying disjoints')
    for d in Drug.disjoints():
        print('\t', d.entities)
    # entities属性是可写入的owlready使用AllDisjoint或AllDifferent， 
    # OWL使用disjointWith, propertyDisjointWith
    print('5. closing individuals')
    class has_for_active_principle(Drug >> ActivePrinciple): pass
    # 下面的my_acetaminophen_drug含有活性成分acetaminophen, 实际上他也可能含有其它活性成分
    my_acetaminophen_drug = Drug(has_for_active_principle = [acetaminophen])
    # 如果不期望它含有其它的活性成分则需要如下处理, OneOf会将acetaminophen个体转化成一个对象, 以便可以使用它在限制(restriction)中
    my_acetaminophen_drug.is_a.append(has_for_active_principle.only(OneOf([acetaminophen])))
    # 很快会发现在开放世界假设通常会导致一长串的区别(AllDifference)和限制(Restrictions)
    # owlready2支持close_word()方法通过添加ONLY限制来自动'closing'个体
    # 该方法支持可选参数来列举需要关闭的属性, 默认会关闭所有domain与个体相容（compatible)的属性)
    close_world(my_acetaminophen_drug)
    print(my_acetaminophen_drug)
    # close_word也支持类